package org.vergil.core.thread.productionmessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by vergil on 17-3-18.
 */
@Component
public class Producer implements Runnable {

    @Autowired
    private Business business;
    private int flag = 1;

//    public Producer(Business business) {
//        this.business = business;
//    }

    @Override
    public void run() {
        while (true) {
            List<Map<String,Object>> list = new ArrayList<>();
            for (int i = 0 ; i< 10 ; i ++ ) {
                Map<String, Object> map = new HashMap<>();
                map.put("id", flag);
                list.add(map);
                flag++;
            }
            try {
                synchronized (this){
                    business.push(list);
                }
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
    }
}
}
